﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;

namespace Idlesoft.Utils
{
	public static class TypeConverterExtensions
	{
		public static TypeConverter Converter(this Type type)
		{
			return TypeDescriptor.GetConverter(type);
		}
		public static TypeConverter Converter<TItem>(this TItem item)
		{
			return TypeDescriptor.GetConverter(item);
		}
		public static string ConvertToInvariantString<TItem>(this TItem item)
		{
			return TypeDescriptor.GetConverter(item).ConvertToInvariantString(item);
		}
		public static TItem ConvertFromInvariantString<TItem>(this string text)
		{
			return (TItem)TypeDescriptor.GetConverter(typeof(TItem)).Converter().ConvertFromInvariantString(text);
		}
		public static string ConvertFrom<TItem>(this TItem item)
		{
			return (string)TypeDescriptor.GetConverter(item).ConvertFrom(item);
		}
		public static TItem ConvertFrom<TItem>(this string text)
		{
			return (TItem)TypeDescriptor.GetConverter(typeof(TItem)).ConvertFrom(text);
		}
	}
}
